package com.jz.community.modulemine.message.ui;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.alibaba.fastjson.JSONObject;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.modulemine.R;
import com.jz.community.modulemine.message.bean.MessageListBean;

import java.util.List;


/**
 * Created by Ani_H on 2018/2/24.
 */

public class NoticeAdapter extends BaseQuickAdapter<MessageListBean.EmbeddedBean.JpushMessageLogsBean, BaseViewHolder> {

    public NoticeAdapter(int layoutResId, @Nullable List<MessageListBean.EmbeddedBean.JpushMessageLogsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageListBean.EmbeddedBean.JpushMessageLogsBean entity) {
        //小红点 0 未读 1已读
        int isRead = entity.getReadflag();

        ImageView redPoint = helper.getView(R.id.item_notice_point);

        if (isRead == 0) {
            //未读
            redPoint.setVisibility(View.VISIBLE);
        } else {
            //已读
            redPoint.setVisibility(View.INVISIBLE);
        }

        //标题
        helper.setText(R.id.item_notice_title, "系统消息");

        //时间
        helper.setText(R.id.item_notice_time, entity.getCreateTime());

        //内容
        String extras = entity.getContent();
        JSONObject jsonObject = JSONObject.parseObject(extras);
        String content = jsonObject.getString("content").trim();

        helper.setText(R.id.item_notice_content, content);

        //分割线
        ImageView line = helper.getView(R.id.item_notice_line);

        if (helper.getAdapterPosition() != mData.size() - 1) {
            line.setVisibility(View.VISIBLE);
        } else {
            line.setVisibility(View.GONE);
        }

    }
}
